﻿using Pay.Core;
using Pay.DTO;
using Pay.IService;
using Pay.TO;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace Pay.Web.Areas.Admin.Controllers
{
    [RouteArea("admin")]
    [RoutePrefix("playingTeam")]
    public class PlayingTeamController : AdminController
    {
        private IPlayingTeamService _iPlayingTeamService;

        public PlayingTeamController(IPlayingTeamService iPlayingTeamService)
        {
            _iPlayingTeamService = iPlayingTeamService;
        }

        public ActionResult Index()
        {
            return View();
        }

        public JsonResult Gets(PlayingTeamQuery query)
        {
            var model = _iPlayingTeamService.GetPlayingTeams(query);
            return Json(ResultToJson.Json(model), JsonRequestBehavior.AllowGet);
        }

        public JsonResult Get(long id)
        {
            playing_team_dto model = new playing_team_dto();
            if (id > 0)
                _iPlayingTeamService.GetPlayingTeam(id).ToCopyProperty(model);
            return Json(ResultToJson.Json(model), JsonRequestBehavior.AllowGet);
        }

        [HttpPost]
        [ValidateInput(false)]
        public JsonResult Add(playing_team_dto dto)
        {
            var file_url = Upload("playing_team");
            if (!string.IsNullOrEmpty(file_url))
                dto.img_url = file_url;
            else
                return Json(ResultToJson.Json(1001, "请先上传图片", new { }), JsonRequestBehavior.AllowGet);
            var result = _iPlayingTeamService.AddPlayingTeam(dto);
            return Json(ResultToJson.Json(result > 0 ? " 保存成功" : "保存失败", result), JsonRequestBehavior.AllowGet);

        }

        [HttpPost]
        [ValidateInput(false)]
        public JsonResult Update(playing_team_dto dto)
        {
            var file_url = Upload("playing_team");
            if (!string.IsNullOrEmpty(file_url))
                dto.img_url = file_url;

            var result = _iPlayingTeamService.UpdatePlayingTeam(dto);
            return Json(ResultToJson.Json(result > 0 ? " 保存成功" : "未做任何修改", result), JsonRequestBehavior.AllowGet);

        }


    }
}